<template>
    <div class="about">
		<!-- <banner isHome="true"></banner> -->
        <div class="site-content">
            <div class="content-warp">
                <div class="about-me about-info">
                    <section-title id="Guestbook"><span>❤</span>全部社团</section-title>
					<el-button @click="appliationVO=true">申请社团</el-button>
                    <div class="info-card" v-for="item in club">
                        <div class="contactForm">
							<div class="focusinfo">
							    <img :src="item.src">
							</div>
							<ul class="list-group list-group-striped">
								<li class="list-group-item">
									社团名称:{{item.name}}
								</li>
								<li class="list-group-item">
									社团详情:{{item.detail}}
								</li>
								<button style="margin-top: 10px;" v-if="item.userStatus!=1" @click="come(item.id)">加入社团</button>
							</ul>
                        </div>
                    </div>
					<!-- 申请社团 -->
					<el-dialog title="申请社团" :visible.sync="appliationVO" width="500px" append-to-body>
						文章图片：
						<el-image
						    style="width: 100px; height: 100px"
						    :src="photo"
						    :zoom-rate="1.2"
								 fit="cover"
						/>
						<el-upload
							drag
							action="http://localhost:8090/upload/image"
							name="multipartFile"
							:on-success="uploadImageSuccess"
						></el-upload>
					  社团名字：<el-input v-model="clubName"/>
					  社团详情：<el-input v-model="clubDescription"/>
					  </el-form>
					  <div slot="footer" class="dialog-footer">
					    <el-button type="primary" @click="appliation()">确 定</el-button>
					    <el-button @click="cancel">取 消</el-button>
					  </div>
					</el-dialog>
					
					<!-- 选择部门 -->
					<el-dialog title="选择部门" :visible.sync="open" width="500px" append-to-body>
					  <el-form ref="form" :model="user" label-width="80px">
					    <el-form-item label="修改" >
							<el-select v-model="valueDep" clearable placeholder="请选择部门">
							  <el-option
								v-for="item in clubDep"
								:key="item.id"
								:label="item.name"
								:value="item.id">
							  </el-option>
							</el-select>
					    </el-form-item>
					  </el-form>
					  <div slot="footer" class="dialog-footer">
					    <el-button type="primary" @click="submit()">确 定</el-button>
					    <el-button @click="cancel">取 消</el-button>
					  </div>
					</el-dialog>
					
					<div class="more" v-show="hasNextPage">
						<div class="more-btn" @click="loadMore">More</div>
					</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
	import sectionTitle from '@/components/section-title'
	import { getAllClub } from '@/api/club'
	import { getCLubDep, insertClubUser, clubApplication } from '../../api/manager'
    export default {
        name: "About",
        data() {
            return {
				club: [],
				currPage: 1,
				hasNextPage: true,
				valueDep: '',
				clubDep: [],
				open: false,
				clubId: '',
				clubName: '',
				clubDescription: '',
				appliationVO: false,
				photo: ''
            }
        },
        components: {
			sectionTitle
            // Quote,
        },
        methods: {
			uploadImageSuccess(response, uploadFile, uploadFiles){
				this.photo = response.photo
			},
			async get() {
				let data = await getAllClub({
					pageNum: this.currPage,
					pagesize: 5
				})
				this.club = data.clubs
			},
			async loadMore() {
			    // fetchList({page:this.currPage+1}).then(res => {
			    //     this.postList = this.postList.concat(res.data.items || [])
			    //     this.currPage = res.data.page
			    //     this.hasNextPage = res.data.hasNextPage
			    // })
				this.currPage = this.currPage + 1
				let data = await getAllClub({
					pageNum: this.currPage,
					pagesize: 5
				})
				this.club = this.club.concat(data.clubs || [])
			},
			async come(id) {
				let data = await getCLubDep(id)
				this.clubId = id
				this.clubDep = data.department
				this.open = true
			},
			cancel() {
			  this.open = false
			  this.appliationVO = false
			  this.clubId = ''
			  this.valueDep = ''
			  this.clubName = ''
			  this.clubDescription = ''
			  this.photo = ''
			},
			async submit() {
				if (this.valueDep == '') {
					alert("未选择部门")
					return
				}
				// 加入社团代码
				await insertClubUser({
					clubId: this.clubId,
					departmentId: this.clubDep
				})
				this.open = false
				this.clubId = ''
				this.valueDep = ''
			},
			async appliation() {
				// 申请社团接口代码
				if (this.clubName == '') {
					alert("社团名字不能为空")
					return
				}
				await clubApplication({
					name: this.clubName,
					detail: this.clubDescription
				})
				alert("添加成功")
				this.cancel()
			}
		},
        mounted() {
			this.currPage = 1
			this.get()
        }
    }
</script>

<style scoped lang="less">
    .about {
        padding-top: 40px;
    }
	
	.list-group-striped > .list-group-item {
		border-left: 0;
		border-right: 0;
		border-radius: 0;
		padding-left: 0;
		padding-right: 0;
	}
	.list-group-item {
		border-bottom: 1px solid #e7eaec;
		border-top: 1px solid #e7eaec;
		margin-bottom: -1px;
		padding: 11px 0;
		font-size: 13px;
	}
	.pull-right {
		float: right !important;
	}
	.focusinfo {
	    position: relative;
	    max-width: 800px;
	    padding: 0 10px;
	    top: 40%;
	    left: 50%;
	    transform: translate(-50%,-50%);
	    -webkit-transform: translate(-50%,-50%);
	    text-align: center;
	    img {
			margin-top: 100px;
	        width: 80px;
	        height: 80px;
	        border-radius: 50%;
	        border: 3px solid rgba(255, 255, 255, 0.3);
	    }
	}
	
	.more{
	    margin: 50px 0;
	    .more-btn{
	        width: 100px;
	        height: 40px;
	        line-height: 40px;
	        text-align: center;
	        color: #ADADAD;
	        border: 1px solid #ADADAD;
	        border-radius: 20px;
	        margin: 0 auto;
	        cursor: pointer;
	        &:hover{
	            color: #8fd0cc;
	            border: 1px dashed #8fd0cc;
	        }
	    }
	}


    .content-warp {
        margin-top: 80px;

        .about-info {
            margin: 30px 0;

            span {
                color: red;
                margin-right: 10px;
            }

            .info-card {
                min-height: 100px;
                padding: 20px;
                border-radius: 3px;
                margin: 30px 0 50px 0;
                box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                p{
                    line-height: 1.7rem;
                }
            }
        }
        .contactForm{
			text-align: center;
            width: 100%;
            padding: 20px;
            .form-item{
                align-items: center;
                display: flex;
                &:not(:last-child){
                    margin-bottom: 20px;
                }
                label{
                  width: 80px;
                }
                .v{
                    min-height: 40px;
                    line-height: 20px;
                    border-radius: 3px;
                    padding: 2px 10px;
                    outline:none;
                    border: 1px solid #8fd0cc;
                    width: 100%;
                    resize: vertical;
                }
                button{
                    width: 100px;
                    height: 40px;
                    border-radius: 3px;
                    outline:0;
                    border-style: none;
                    cursor: pointer;
                    background-color: #409eff;
                    color: white;
                    &:hover{
                        opacity: 0.8;
                    }
                }
            }
        }
    }

    /*******/
    @media (max-width: 800px) {
        .content-warp {
            margin-top: 0;
        }
    }
</style>